﻿using Prism.Navigation.Regions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;

namespace PrismRegion.Navigation.ViewModels
{
    public class MainWindowViewModel
    {
        private readonly IRegionManager _regionManager;

        public ICommand OpenViewCommand { get; set; }
        public MainWindowViewModel(IRegionManager regionManager)
        {
            OpenViewCommand = new DelegateCommand<string>(DoOpenView);
            _regionManager = regionManager;
        }

        private void DoOpenView(string viewName)
        {
            //bool bl = _regionManager.Regions["ViewRegion"].Views.Contains(viewName);
            //if (!bl)
            //{
            //    // 无法传参
            //    _regionManager.RegisterViewWithRegion("ViewRegion", viewName);                
            //}
            //var region = _regionManager.Regions["ViewRegion"];
            //var view = region.Views.FirstOrDefault(v => v.GetType().Name == viewName);
            //region.Activate(view);

            //_regionManager.RequestNavigate("ViewRegion", viewName);

            NavigationParameters parameters = new NavigationParameters();
            parameters.Add("abcd","aaaa"+ viewName);
            _regionManager.RequestNavigate("ViewRegion", viewName, parameters);
        }
    }
}
